﻿using System;

namespace EmbeddedSharp.Core.Function.Arithmetics {

    /// <summary>
    /// a = 1*2;
    /// echo(a);
    /// # result is 2
    /// </summary>
    public class MulNode : OperatorNode {
        public MulNode()
            : base() {
            base.Value = "*";
            Precedence = 2;
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }

        public override FuncNode GetReversedFunction(int index) {
            return new DivNode();
        }

        public override object Evaluate() {
            double lr = Convert.ToDouble(
                Left.Evaluate());
            double rr = Convert.ToDouble(
                Right.Evaluate());

            return (lr * rr).ToString();
        }
    }
}
